﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Collections;
using Microsoft.ApplicationBlocks.Data;
namespace kxjsj
{
    public partial class count : Form
    {
        OleDbConnection con;
        public string sql;
        public string sql2;
        public count()
        {
            InitializeComponent();
            string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + System.Windows.Forms.Application.StartupPath + "\\data\\kxjsj.mdb";
            con = new OleDbConnection(constr);
            con.Open();
        }

        private void count_Load(object sender, EventArgs e)
        {
            OleDbDataAdapter sda= new OleDbDataAdapter(sql, con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "huizong");
            if (sql2 != "")
            {
                sda = new OleDbDataAdapter(sql2, con);
                sda.Fill(ds, "xms");
            }
            this.dataGridView1.DataSource = ds.Tables["huizong"].DefaultView;
            toolStripTextBox1.Text = "行数："+ds.Tables["huizong"].Rows.Count .ToString();
            if(sql2!="")
                toolStripTextBox2.Text = "项目数：" + ds.Tables["xms"].Rows.Count.ToString();
        }

        private void 导出至excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            get_flds g_f = new get_flds();

            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                g_f.flds.Add(dataGridView1.Columns[i].HeaderText);
            }
            if (g_f.ShowDialog() == DialogResult.OK)
            {
                helper.DataGridViewToExcel(dataGridView1, g_f.flds_to_output);
            }
            g_f.Dispose();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            count_Load(null, null);
        }
    }
}
